﻿using CivitaiAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CivitaiCLI.Utils
{
    public static class CivitaiUtil
    {
        public static string ShortFormat(this TimeSpan t, bool pad = false)
        {
            string shortForm = "";
            //bool hasHours = t.Hours > 0;
            bool hasMinutes = t.Minutes > 0;
            bool hasSeconds = t.Seconds > 0;
            //if (hasHours)
            //    shortForm += $"{t.Hours}h";
            if (hasMinutes)
                shortForm += $"{t.Minutes}m";
            if (hasSeconds)
                shortForm += $"{t.Seconds}s";

            if (!hasMinutes && !hasSeconds)
                shortForm += "0s";
            return pad ? shortForm.PadLeft(6) : shortForm;
        }

        public static List<string> GetAllPrompts(this ModelInfo model)
        {
            List<string> result = new List<string>();

            if (model.modelVersions != null)
            {
                for (int l = 0; l < model.modelVersions.Count; l++)
                {
                    if (model.modelVersions[l].images != null)
                    {
                        for (int k = 0; k < model.modelVersions[l].images.Count; k++)
                        {
                            result.Add(model.modelVersions[l].images[k].FormatMeta());
                        }
                    }
                }
            }

            return result;
        }
    }
}
